Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ShuffleNet ONNX export #7686

Merged
merged 3 commits into from
Jun 22, 2023
Merged

Fix ShuffleNet ONNX export #7686

merged 3 commits into from
Jun 22, 2023

Conversation

justanhduc
Copy link
Contributor

@justanhduc justanhduc commented Jun 21, 2023

When exporting the current model, there's an error as follows

SymbolicValueError: Unsupported: ONNX export of operator prim::ConstantChunk, 
unknown dimension size. Please feel free to request support or submit a pull 
request on PyTorch GitHub: https://github.com/pytorch/pytorch/issues  [Caused by
the value '406 defined in (%406 : Float(*, *, *, *, strides=[249856, 1024, 32, 
1], requires_grad=1, device=cpu) = onnx::Reshape(%403, %405), scope: 
__main__.OnnxModel::/models.ShuffleNetv2x2::net/torchvision.models.shufflenetv2.
ShuffleNetV2::model/torch.nn.modules.container.Sequential::stage2/torchvision.mo
dels.shufflenetv2.InvertedResidual::stage2.0 # 
/home/ubuntu/miniconda3/envs/pt20/lib/python3.8/site-packages/torchvision/models
/shufflenetv2.py:38:0
)' (type 'Tensor') in the TorchScript graph. The containing node has kind 
'onnx::Reshape'.] 
    (node defined in 
/home/ubuntu/miniconda3/envs/pt20/lib/python3.8/site-packages/torchvision/models
/shufflenetv2.py(38): channel_shuffle
/home/ubuntu/miniconda3/envs/pt20/lib/python3.8/site-packages/torchvision/models
/shufflenetv2.py(99): forward
/home/ubuntu/miniconda3/envs/pt20/lib/python3.8/site-packages/torch/nn/modules/m
odule.py(1488): _slow_forward
/home/ubuntu/miniconda3/envs/pt20/lib/python3.8/site-packages/torch/nn/modules/m
odule.py(1501): _call_impl
/home/ubuntu/miniconda3/envs/pt20/lib/python3.8/site-packages/torch/nn/modules/c
ontainer.py(217): forward
/home/ubuntu/miniconda3/envs/pt20/lib/python3.8/site-packages/torch/nn/modules/m
odule.py(1488): _slow_forward
/home/ubuntu/miniconda3/envs/pt20/lib/python3.8/site-packages/torch/nn/modules/m
odule.py(1501): _call_impl
/home/ubuntu/miniconda3/envs/pt20/lib/python3.8/site-packages/torchvision/models
/shufflenetv2.py(157): _forward_impl
/home/ubuntu/miniconda3/envs/pt20/lib/python3.8/site-packages/torchvision/models
/shufflenetv2.py(166): forward
/home/ubuntu/miniconda3/envs/pt20/lib/python3.8/site-packages/torch/nn/modules/m
odule.py(1488): _slow_forward
/home/ubuntu/miniconda3/envs/pt20/lib/python3.8/site-packages/torch/nn/modules/m
odule.py(1501): _call_impl
/home/ubuntu/miniconda3/envs/pt20/lib/python3.8/site-packages/torch/nn/modules/c
ontainer.py(217): forward
/home/ubuntu/miniconda3/envs/pt20/lib/python3.8/site-packages/torch/nn/modules/m
odule.py(1488): _slow_forward
/home/ubuntu/miniconda3/envs/pt20/lib/python3.8/site-packages/torch/nn/modules/m
odule.py(1501): _call_impl
/home/ubuntu/workspace/ducna19/projects/yolox-bytetrack-count/carseat_cls/pt2onn
x.py(36): forward
/home/ubuntu/miniconda3/envs/pt20/lib/python3.8/site-packages/torch/nn/modules/m
odule.py(1488): _slow_forward
/home/ubuntu/miniconda3/envs/pt20/lib/python3.8/site-packages/torch/nn/modules/m
odule.py(1501): _call_impl
/home/ubuntu/miniconda3/envs/pt20/lib/python3.8/site-packages/torch/jit/_trace.p
y(118): wrapper
/home/ubuntu/miniconda3/envs/pt20/lib/python3.8/site-packages/torch/jit/_trace.p
y(127): forward
/home/ubuntu/miniconda3/envs/pt20/lib/python3.8/site-packages/torch/nn/modules/m
odule.py(1501): _call_impl
/home/ubuntu/miniconda3/envs/pt20/lib/python3.8/site-packages/torch/jit/_trace.p
y(1268): _get_trace_graph
/home/ubuntu/miniconda3/envs/pt20/lib/python3.8/site-packages/torch/onnx/utils.p
y(893): _trace_and_get_graph_from_model
/home/ubuntu/miniconda3/envs/pt20/lib/python3.8/site-packages/torch/onnx/utils.p
y(989): _create_jit_graph
/home/ubuntu/miniconda3/envs/pt20/lib/python3.8/site-packages/torch/onnx/utils.p
y(1113): _model_to_graph
/home/ubuntu/miniconda3/envs/pt20/lib/python3.8/site-packages/torch/onnx/utils.p
y(1548): _export
/home/ubuntu/miniconda3/envs/pt20/lib/python3.8/site-packages/torch/onnx/utils.p
y(506): export
/home/ubuntu/workspace/ducna19/projects/yolox-bytetrack-count/carseat_cls/pt2onn
x.py(69): main
/home/ubuntu/workspace/ducna19/projects/yolox-bytetrack-count/carseat_cls/pt2onn
x.py(113): <module>
)

    Inputs:
        #0: 403 defined in (%403 : Float(*, *, *, *, *, strides=[249856, 2048, 
1024, 32, 1], requires_grad=1, device=cpu) = onnx::Transpose[perm=[0, 2, 1, 3, 
4]](%402), scope: 
__main__.OnnxModel::/models.ShuffleNetv2x2::net/torchvision.models.shufflenetv2.
ShuffleNetV2::model/torch.nn.modules.container.Sequential::stage2/torchvision.mo
dels.shufflenetv2.InvertedResidual::stage2.0 # 
/home/ubuntu/miniconda3/envs/pt20/lib/python3.8/site-packages/torchvision/models
/shufflenetv2.py:35:0
    )  (type 'Tensor')
        #1: 405 defined in (%405 : int[] = prim::ListConstruct(%382, %404, %391,
%396), scope: 
__main__.OnnxModel::/models.ShuffleNetv2x2::net/torchvision.models.shufflenetv2.
ShuffleNetV2::model/torch.nn.modules.container.Sequential::stage2/torchvision.mo
dels.shufflenetv2.InvertedResidual::stage2.0
    )  (type 'List[int]')
    Outputs:
        #0: 406 defined in (%406 : Float(*, *, *, *, strides=[249856, 1024, 32, 
1], requires_grad=1, device=cpu) = onnx::Reshape(%403, %405), scope: 
__main__.OnnxModel::/models.ShuffleNetv2x2::net/torchvision.models.shufflenetv2.
ShuffleNetV2::model/torch.nn.modules.container.Sequential::stage2/torchvision.mo
dels.shufflenetv2.InvertedResidual::stage2.0 # 
/home/ubuntu/miniconda3/envs/pt20/lib/python3.8/site-packages/torchvision/models
/shufflenetv2.py:38:0
    )  (type 'Tensor')

Process finished with exit code 1

Replacing -1 by num_channels fixed this problem.

cc @neginraoof @justinchuby

@pytorch-bot
Copy link

pytorch-bot bot commented Jun 21, 2023

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/vision/7686

Note: Links to docs will display an error until the docs builds have been completed.

❌ 28 New Failures, 2 Unrelated Failures

As of commit 224d2d0:

NEW FAILURES - The following jobs have failed:

BROKEN TRUNK - The following jobs failed but were present on the merge base b5401b9:

👉 Rebase onto the `viable/strict` branch to avoid these failures

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@facebook-github-bot
Copy link

Hi @justanhduc!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

Copy link
Member

@NicolasHug NicolasHug left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR @justanhduc .

LGTM when green. We'll need you to approve the CLA before merging.

@justanhduc
Copy link
Contributor Author

@NicolasHug There are some failed tests. Is there anything I should do?

@NicolasHug NicolasHug changed the title used explicit shape rather than -1 to avoid onnx export failure Fix ShuffleNet ONNX export Jun 22, 2023
@NicolasHug
Copy link
Member

They're unrelated, I'll merge the PR now. Thanks for the fix!

@NicolasHug NicolasHug merged commit f02caa5 into pytorch:main Jun 22, 2023
@justanhduc justanhduc deleted the patch-1 branch June 27, 2023 15:08
facebook-github-bot pushed a commit that referenced this pull request Jul 3, 2023
Summary: Co-authored-by: Nicolas Hug <nh.nicolas.hug@gmail.com>

Reviewed By: vmoens

Differential Revision: D47186582

fbshipit-source-id: 39536fb01a321fb110a3fcd28b670e3cd28f12e7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants